<%@page import="java.util.Map"%>
<%@page import="cts.com.dbmanager.DepositWithdrawlCash"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<style type="text/css">
a{
color: blue;
}
</style>
<script>
	function callAddBeneficiary() {
		var xmlhttp;
		var pAcNo = document.getElementById("txtPrimaryAcNo").value;
		var bAcNo = document.getElementById("txtBeneficiaryAcNo").value;
		var bAcName = document.getElementById("txtBeneficiaryName").value;
		var bIFSC = document.getElementById("txtBeneficiaryIFSC").value;
		var bEmail = document.getElementById("txtBeneficiaryEmail").value;
		var bPhNo = document.getElementById("txtBeneficiaryPhNo").value;
		var bBankName = document.getElementById("txtBeneficiaryBank").value;
		
		if (pAcNo.length == 0 && bAcNo.length == 0) {
			document.getElementById("txtHint").innerHTML = "Enter Primary A/c No as well as Beneficiary A/c No";
			return;
		}
		if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp = new XMLHttpRequest();
		} else {// code for IE6, IE5
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
				document.location.reload(true);
			}
		}

		xmlhttp.open("POST", "availableBalance.do", true);
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttp.send("txtPrimaryAcNo=" + pAcNo + "&txtBeneficiaryAcNo=" + bAcNo
				+ "&txtBeneficiaryName=" + bAcName + "&txtBeneficiaryIFSC="
				+ bIFSC + "&txtBeneficiaryEmail=" + bEmail
				+ "&txtBeneficiaryPhNo=" + bPhNo+"&txtBeneficiaryBank="+bBankName
				+ "&operation=addBeneficiary&sameBank=false");
	}

	function callDeleteBeneficiary(primaryAcNo,beneficiaryAcNo) {
		var xmlhttp;
		alert(primaryAcNo+"  "+beneficiaryAcNo);
		if (primaryAcNo.length == 0 && beneficiaryAcNo.length == 0) {
			document.getElementById("txtHint").innerHTML = "Either Primary or Beneficiary A/c No is Empty";
			return;
		}
		if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp = new XMLHttpRequest();
		} else {// code for IE6, IE5
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
				document.location.reload(true);
			}
		}

		xmlhttp.open("POST", "availableBalance.do", true);
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttp.send("txtPrimaryAcNo=" + primaryAcNo + "&txtBeneficiaryAcNo=" + beneficiaryAcNo
				+ "&operation=deleteBeneficiary&sameBank=false");
	}
</script>

</head>
<body>
	<center>
		<h1>Beneficiary Account in Non-Cognizant Bank</h1><br/>
		<table border="1" width="300" bgcolor="#CED8F6">
			<tr>
				<td colspan="8"><div id="txtHint"></div></td>
			</tr>
			<tr>
				<td><b>Primary Account No.:</b></td>
				<td><b>Beneficiary Bank Name:</b></td>
				<td><b>Beneficiary Account No.:</b></td>
				<td><b>Account Name:</b></td>
				<td><b>IFSC:</b></td>
				<td><b>Email:</b></td>
				<td><b>Phone No.:</b></td>
				<td colspan="2"><b>Operation</b></td>
			</tr>
			<%
				DepositWithdrawlCash dCash = new DepositWithdrawlCash();
				String columnNames = " b.Primary_Account_Id,b.Beneficiary_Bank,b.Beneficiary_Ac_No,"
						+ "b.Beneficiary_Name,b.Beneficiary_IFSC,b.Beneficiary_Email,b.Beneficiary_Ph_No ";
				String tableNames = "AccountInformation a,BENEFICIARY_ACCOUNT b";
				String condition = " where a.Account_Id=b.Primary_Account_Id and a.Bank_Name<>b.Beneficiary_Bank and a.Account_Id='12345'";
				Map<Integer, String[]> map = dCash.getDataFromTablesUsingCondition(
						columnNames, tableNames, condition);
				for (String[] str : map.values()) {
			%>
			<tr>
				<%
					for (String s : str) {
				%>

				<td><%=s%></td>
				<%
					}
				%>
				<td><a href="#" onclick="callDeleteBeneficiary('<%=str[0] %>','<%=str[2] %>')">Remove</a></td>
			</tr>
			<%
				}
			%>


			<tr>
				<td><input type="text" readonly="readonly" id="txtPrimaryAcNo"
					name="txtPrimaryAcNo" size="20" value="12345"/></td>
				<td>
					<select id="txtBeneficiaryBank">
						<option value="HDFC">HDFC</option>
						<option value="ICICI">ICICI</option>
						<option value="SBI">SBI</option>
						<option value="AXIS">AXIS</option>
						<option value="CITI">CITI</option>
					</select>	
				</td>
				<td><input type="text" id="txtBeneficiaryAcNo"
					name="txtBeneficiaryAcNo" size="15" /></td>
				<td><input type="text" id="txtBeneficiaryName"
					name="txtBeneficiaryName" size="15" /></td>
				<td><input type="text" id="txtBeneficiaryIFSC"
					name="txtBeneficiaryIFSC" size="8" /></td>
				<td><input type="text" id="txtBeneficiaryEmail"
					name="txtBeneficiaryEmail" size="15" /></td>
				<td><input type="text" id="txtBeneficiaryPhNo"
					name="txtBeneficiaryPhNo" size="10" /></td>

				<td><a href="#" onclick="callAddBeneficiary()">Add</a></td>
			</tr>
		</table>
		<a href="index.jsp">Back</a>
	</center>
</body>
</html>